package cn.wolfcode.shop.cloud.advice;

import cn.wolfcode.shop.cloud.BusinessException;
import cn.wolfcode.shop.cloud.CommonControllerAdvice;
import cn.wolfcode.shop.cloud.Result;
import cn.wolfcode.shop.cloud.msg.MemberCodeMsg;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
public class MemberControllerAdvice extends CommonControllerAdvice {

    @ExceptionHandler(BindException.class)
    @ResponseBody
    public Result handler(BindException exception) {
        String defaultMessage = exception.getAllErrors().get(0).getDefaultMessage();

        exception.printStackTrace();
        MemberCodeMsg memberCodeMsg = MemberCodeMsg.PARAM_ERROR;
        memberCodeMsg = memberCodeMsg.filterArg(defaultMessage);
        return Result.error(memberCodeMsg);

    }


}
